package com.jhgk.jhcee.common.resultful;

import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.enums.BasisResultTemplate;
import lombok.Data;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/6 10:08.
 */
@Data
public class VbenResultful<T> {
    private long code;
    private String message;
    private String type;
    private T result;

    private VbenResultful() {

    }

    VbenResultful(long code, String message, String type) {
        this.code = code;
        this.message = message;
        this.type = type;
        this.result = null;
    }

    VbenResultful(long code, String message, String type, T result) {
        this.code = code;
        this.message = message;
        this.type = type;
        this.result = result;
    }

    VbenResultful(BasisResultTemplate basisResultTemplate, T result) {
        this.code = basisResultTemplate.getCode();
        this.message = basisResultTemplate.getMessage();
        this.result = result;
    }

    VbenResultful(BasisResultTemplate basisResultTemplate) {
        this.code = basisResultTemplate.getCode();
        this.message = basisResultTemplate.getMessage();
        this.result = null;
    }

    public static <T> VbenResultful<T> success(T result) {
        return new VbenResultful<>(BasisResultEnum.SUCCESSFUL,result);
    }

    public static <T> VbenResultful<T> success() {
        return new VbenResultful<>(BasisResultEnum.SUCCESS);
    }

    public static <T> VbenResultful<T> fail() {
        return new VbenResultful<>(BasisResultEnum.FAIL);
    }

    public static <T> VbenResultful<T> fail(BasisResultTemplate template) {
        return new VbenResultful<>(template);
    }
}
